package com.dp.service.impl;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.dp.pub.MyServer;

//import com.dp.pub.MyServer;
//import com.dp.pub.SysProperty;
//import com.dp.service.impl.AdServiceImpl;
//import com.dp.service.impl.CatalogServiceImpl;
//import com.dp.service.impl.ClientInfoServiceImpl;
//import com.dp.service.impl.ContentServiceImpl;
//import com.dp.service.impl.RssServiceImpl;

import java.util.Arrays;

/**
 * 
 * 项目名称：backend 
 * 类名称：QuartzJob_Publishtitle 
 * 类描述：立即发布频道，Quartz调度器 每5分钟启动一次
 * 创建人：bin.deng 
 * 创建时间：Sep 28, 2009 15:31:18 PM
 * 
 * @version
 * 
 */
public class QuartzJob_PublishChannel implements Job {
	private static Logger log;

	public void execute(JobExecutionContext context)
			throws JobExecutionException {
		String updatetimer = "0";
		boolean flag = false;
		log = Logger.getLogger(this.getClass());
		//ContentServiceImpl contentServiceImpl = new ContentServiceImpl();
		ContentServiceImpl contentServiceImpl =(ContentServiceImpl)MyServer.ctx.getBean("contentServiceImpl");
		String jobName = context.getJobDetail().getName();
		log.info(jobName + " fired at " + new Date());
		String channelidlist = "";
		channelidlist = contentServiceImpl.updateNctContentstatusByJob(updatetimer);

		/* 原“广告定时发布”定时器： */
		//AdServiceImpl adServiceImpl = new AdServiceImpl();
//		AdServiceImpl adServiceImpl =(AdServiceImpl)MyServer.ctx.getBean("adServiceImpl");
		String channelidlist2 = "";
//		channelidlist2 = adServiceImpl.updateNctContentstatusByJob(updatetimer); // 0：默认定时器

		// 将两个channelidlist合并
//		String channelidlistAll = channelidlist;
//		if (!"".equals(channelidlistAll)) { // channelidlist不为空
//			String[] list1 = channelidlist.split(",");
//			String[] list2 = channelidlist2.split(",");
//			for (int i = 0; i < list1.length; i++) {
//				for (int j = 0; j < list2.length; j++) {
//					if (list1[i].equals(list2[j])) {
//						list2[j] = "";
//					}
//				}
//			}
//			for (int i = 0; i < list2.length; i++) {
//				if (list2[i] != null && !"".equals(list2[i])) {
//					channelidlistAll += "," + list2[i];
//				}
//			}
//		} else {
//			channelidlistAll = channelidlist2;
//		}
		String channelidlistAll ="";
		Set<String> channelidSet = new HashSet<String>();
		channelidSet.addAll(Arrays.asList(channelidlist.split(",")));
		channelidSet.addAll(Arrays.asList(channelidlist2.split(",")));
		channelidSet.remove("");
		for(String ciddd:channelidSet)channelidlistAll+=","+ciddd;
		
		log.info("----------"+channelidlistAll);
		if(!"".equals(channelidlistAll))channelidlistAll=channelidlistAll.substring(1);
		log.info("----------"+channelidlistAll);
		if (!"".equals(channelidlistAll)) {
			CatalogServiceImpl catalogService = new CatalogServiceImpl();
			catalogService.rePublishtitleURL(channelidlistAll);
		}

		//是否超过最大用户数
//		ClientInfoServiceImpl clientInfoServiceImpl =(ClientInfoServiceImpl)MyServer.ctx.getBean("clientInfoServiceImpl");
//		clientInfoServiceImpl.maxclientcount();
	}
}
